﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Class_KetNoi;

namespace GiaoDien
{
    public partial class uc_QuanTriNguoiDung : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_QuanTriNguoiDung()
        {
            InitializeComponent();
        }
        KetNoi_NguoiDung kn = new KetNoi_NguoiDung();
        public void LoadDuLieu()
        {
            string sql = "select * from tbl_NguoiDung";
            gridControl1.DataSource = kn.taobang(sql);
        }
        private void uc_QuanTriNguoiDung_Load(object sender, EventArgs e)
        {
            kn.connect();
            LoadDuLieu();
        }
        int flag;
        private void btnThem_Click(object sender, EventArgs e)
        {
            flag = 0;
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            flag = 1;
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            kn.xoa_NguoiDung(txtMaNhanVien.Text);
            LoadDuLieu();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (flag == 0)
            {
                kn.them_NguoiDung(txtTenDangNhap.Text, txtMaNhanVien.Text, txtMatKhau.Text, txtMaPhanQuyen.Text);
            }
            if (flag == 1)
            {
                kn.sua_NguoiDung(txtTenDangNhap.Text, txtMaNhanVien.Text, txtMatKhau.Text, txtMaPhanQuyen.Text);
            }
            LoadDuLieu();
        }
    }
}
